import { Component, OnInit, ViewChild } from '@angular/core';
import { _HttpClient } from '@delon/theme';
import { SupDic, HttpService } from 'lbf';
import { SFSchema, SFComponent } from '@delon/form';
import { ReuseTabService } from '@delon/abc';
import { ActivatedRoute } from '@angular/router';
import { NzMessageService } from 'ng-zorro-antd';

@Component({
  selector: 'app-zwyb-lqylpz',
  templateUrl: './lqylpz.component.html',
})
export class ZwybLqylpzComponent implements OnInit {
  constructor(
    private http: _HttpClient,
    private supDic: SupDic,
    private reuseTabService: ReuseTabService,
    private activateroute: ActivatedRoute,
    private lbservice: HttpService,
    public msgSrv: NzMessageService,
  ) {}

  @ViewChild('sf', { static: false }) sf: SFComponent;
  @ViewChild('sf1', { static: false }) sf1: SFComponent;

  bdSchema: SFSchema = {
    properties: {
      AAC050: {
        type: 'string',
        title: '补换证历本类型',
        enum: this.supDic.getSFDic('AAC050'),
      },
      BKE570: {
        type: 'string',
        title: '领取对象',
      },
      AAC002: {
        type: 'string',
        title: '领取人身份证',
      },
      AAC003: {
        type: 'string',
        title: '领取人姓名',
      },
      AAB301: {
        type: 'string',
        title: '统筹区编码',
        enum: this.supDic.getSFDic('AAA027'),
      },
    },
    ui: {
      spanLabelFixed: 100,
      grid: { span: 6 },
    },
  };

  yjSchema: SFSchema = {
    properties: {
      provinceCode: {
        type: 'string',
        title: '省编码',
      },
      provinceName: {
        type: 'string',
        title: '省份',
      },
      cityCode: {
        type: 'string',
        title: '市编码',
      },
      cityName: {
        type: 'string',
        title: '城市',
      },
      districtCode: {
        type: 'string',
        title: '区编码',
      },
      districtName: {
        type: 'string',
        title: '区名',
      },
      streetCode: {
        type: 'string',
        title: '街道编码',
      },
      streetName: {
        type: 'string',
        title: '街道',
      },
      villageCode: {
        type: 'string',
        title: '乡镇编码',
      },
      villageName: {
        type: 'string',
        title: '乡镇名',
      },
      name: {
        type: 'string',
        title: '收件人姓名',
      },
      phone: {
        type: 'string',
        title: '联系电话',
      },
      postCode: {
        type: 'string',
        title: '邮编',
      },
      address: {
        type: 'string',
        title: '地址',
      },
    },
    ui: {
      spanLabelFixed: 100,
      grid: { span: 6 },
    },
  };

  PROJID = '';
  DAD069 = '';
  DAD017 = '';

  tabMode = 'bjxx';

  ngOnInit() {
    this.reuseTabService.title = '医疗凭证送达';
    this.PROJID = this.activateroute.snapshot.queryParams.PROJID;
    this.DAD069 = this.activateroute.snapshot.queryParams.DAD069;
    this.DAD017 = this.activateroute.snapshot.queryParams.DAD017;
    this.YB_QUERY();
    this.query_yjxx();
  }

  //基本数据查询
  YB_QUERY() {
    this.lbservice
      .lbservice('YB_QUERY', { para: { PROJID: this.PROJID } })
      .then(resdata => {
        if (resdata.code < 1) {
          this.msgSrv.error(resdata.errmsg);
        } else {
          this.sf.formData = JSON.parse(resdata.message);
          this.sf.reset();
        }
      });
  }

  query_yjxx() {
    this.lbservice
      .lbservice('query_yjxx', { para: { PROJID: this.PROJID } })
      .then(resdata => {
        if (resdata.code < 1) {
          this.msgSrv.error(resdata.errmsg);
        } else {
          this.sf1.formData = JSON.parse(resdata.message).toAddress;
          this.sf1.reset();
        }
      });
  }

  //已邮寄信息
  insert_yjxx() {
    this.lbservice
      .lbservice('insert_yjxx', { para: { DAD069: this.DAD069 } })
      .then(resdata => {
        if (resdata.code < 1) {
          this.msgSrv.error(resdata.errmsg);
        } else {
          // alert("成功！");
          this.sf1.reset();
        }
      });
  }

  //事项进度
  selectTab(str: string) {
    this.tabMode = str;
    if (str === 'sxjd') {
    }
  }
  // tslint:disable-next-line:all
  icon1 = 'caret-right';
}
